<?php
$url = "/admin/index.php";
if(file_exists('../config.php')) {
  	Header("Location: $url"); 
}
$config = include '../config.php';
header("Content-Type:text/html; charset=utf-8");

$USER = trim($_POST["USER"]);
$PWDONCE = trim($_POST["PWDONCE"]);
$PWDTWICE = trim($_POST["PWDTWICE"]);

if(isset($USER) && isset($PWDONCE) && isset($PWDTWICE) && $PWDONCE === $PWDTWICE){
	$link = mysql_connect($config["DB_HOST"],$config["DB_USER"],$config["DB_PWD"]) or die("can't connect dbs");//连接MySQL
	mysql_select_db("timeline");//选择数据库
	$pwd = md5($PWDONCE);
	$sql1 = "INSERT INTO  `user` (`username`,`password`) VALUES ('$USER','$pwd')";
	mysql_query($sql1) or die("can't query sql: ". mysql_error());//借SQL语句插入数据

	$sql2 = "INSERT INTO  `timeline` (`type` ,`startDate` ,`endDate` ,`headline` ,`text` ,`tag` ,`asset` ,`status`) VALUES ('1', now() , NULL ,  'test',  'test', NULL , '{media:\'\',caption:\'\',credit:\'\'}', '1')";
	mysql_query($sql2) or die("can't query sql: ". mysql_error());//借SQL语句插入数据
	mysql_close();
	echo "<script>alert('安装成功！'); window.location.href='../';</script>";
}else{	
	return false;
}

?>